/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swa.e_store.userInterface;

import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import swa.e_store.businessLogic.BL_Interface;
import swa.e_store.businessLogic.BL_RemoteFacade;

/**
 *
 * @author Stefan
 */
public class TableListener implements TableModelListener {
    private BL_Interface bLogic;
    
    public TableListener(){
        this.bLogic = new BL_RemoteFacade();
        
    }

    @Override
    public void tableChanged(TableModelEvent e) {
        int row = e.getFirstRow();
        int column = e.getColumn();
        
        TableModel model = (TableModel)e.getSource();
        String columnName = model.getColumnName(column);
        Object data = model.getValueAt(row, column);
        
        System.out.println("data: " + data);
        System.out.println("\nrow: " + row);
        
        int artNbr = (Integer)model.getValueAt(row, 0);
        
        
        
        
        switch(column){
            case 0: break;
            case 1: break;
            case 2: //Price
                String tmpPrice = (String) data;
                long price = (new Long(tmpPrice).longValue());

                    bLogic.setPrice(artNbr, price, 0);
                    
                    break;
            case 3: //offerId
                String tmpOffer = (String)data;
                int offer = (new Integer(tmpOffer).intValue());
                
                bLogic.setOffer(artNbr, offer);
                break;
            default: break;
        }
        
        
    }
    
}
